package com.quanyan.runningriding.web.running.Admin;

import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.validation.base.Update;
import com.quanyan.runningriding.entity.vo.run.req.MusicCollectionVo;
import com.quanyan.runningriding.entity.vo.run.resp.MusicCollectionInfoVo;
import com.quanyan.runningriding.service.RunMusicCollectionService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by liubin on 2016/12/6.
 */
@RestController
@RequestMapping(value = "/admin/api/run")
public class MusicCollectionAdminController {
    @Autowired
    private RunMusicCollectionService runMusicCollectionService;
    private Logger logger = LoggerFactory.getLogger(MusicCollectionAdminController.class);

    @RequestMapping(value = "/insertMusicCollection", method = RequestMethod.POST)
    public APIResponse<?> insertMusicCollection(@RequestBody MusicCollectionVo musicCollectionVo) {
        APIResponse<?> result = runMusicCollectionService.insertMusicCollection(musicCollectionVo);
        return result;
    }

    @RequestMapping(value = "/MusicCollectionList", method = RequestMethod.POST)
    public APIResponse<PageObj<List<MusicCollectionInfoVo>>> musicCollectionList(@RequestBody Map<String, Object> paramMap) {

        PageObj<List<MusicCollectionInfoVo>> result = runMusicCollectionService.musicCollectionList(paramMap);
        return APIResponse.returnSuccess(result);
    }

    @RequestMapping(value = "/updateMusicCollection", method = RequestMethod.POST)
    public APIResponse<?> updateMusicCollection(@RequestBody @Validated(Update.class) MusicCollectionVo MusicCollectionVo) {
        APIResponse<?> result = runMusicCollectionService.updateMusicCollection(MusicCollectionVo);
        return result;
    }

    @RequestMapping(value = "/deleteMusicCollection", method = RequestMethod.POST)
    public APIResponse<?> deleteMusicCollection(@RequestBody Map<String, Object> paramMap) {
        Integer musicCollectionId = MapUtils.getInteger(paramMap, "musicCollectionId");
        APIResponse<?> result = runMusicCollectionService.deleteMusicCollection(musicCollectionId);
        return result;
    }

}
